home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / spamexperts / generate_splash.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  3.3 KB  |  81 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from __future__ import division
  5. import os
  6. import sys
  7. import tempfile
  8. import Image
  9. import ImageDraw
  10. import ImageFont
  11. import ImageEnhance
  12. import ImageOps
  13. import ImageStat
  14. import BmpImagePlugin
  15. import JpegImagePlugin
  16. import PngImagePlugin
  17. Image._initialized = 2
  18. from spamexperts import Version
  19.  
  20. def annotate_splash(original, destination):
  21.     text = 'v%s' % (Version.versions['Apps']['SpamExperts']['Product Version'],)
  22.     annotate(original, text, destination, 'Arial.ttf', 8, (255, 255, 255))
  23.  
  24.  
  25. def professional_splash(name, address, code, original, destination):
  26.     text = 'v%s' % (Version.versions['Apps']['SpamExperts']['Product Version'],)
  27.     annotate(original, text, destination, 'Arial.ttf', 8, (255, 255, 255))
  28.     annotate(destination, name, destination, 'Arial.ttf', 9, (229, 189, 63), 70, True)
  29.     annotate(destination, address, destination, 'Arial.ttf', 9, (229, 189, 63), 55, True)
  30.     annotate(destination, code, destination, 'Arial.ttf', 9, (229, 189, 63), 40, True)
  31.  
  32.  
  33. def annotate(image, text, destination, font = None, size = 10, colour = (0, 0, 0), distance_from_bottom = 22, centre = True):
  34.     ''' Annotate an image with some text and save it to destination.
  35.  
  36.         - `image`: full path of source image, as a string
  37.         - `text` : the string to paste on the image
  38.         - `destination` : full path of image to save, as a string
  39.         - `font` : full path of .pil bitmap font to use
  40.  
  41.                      w
  42.         <--------------------------->
  43.       ^ +---------------------------+
  44.       | |                           |
  45.       | |                           |
  46.       | |                           |
  47.     h | |     (w0,h0)               |
  48.       | |        +---------+        |
  49.       | |        |some text|        | |-> hb
  50.       | |        +---------+(w1,h1) | |-> fromBottomPixels
  51.       v +---------------------------+
  52.             l                   l
  53.          <------>           <------->
  54.                  <--------->
  55.                      wb
  56.     '''
  57.     fromBottomPixels = distance_from_bottom
  58.     if font:
  59.         font = ImageFont.truetype(font, size)
  60.     else:
  61.         font = ImageFont.load_default()
  62.     img = Image.open(image)
  63.     draw = ImageDraw.Draw(img)
  64.     (wb, hb) = font.getsize(text)
  65.     (w, h) = img.size
  66.     if centre:
  67.         w0 = int((w - wb) / 2)
  68.     else:
  69.         w0 = 10
  70.     h0 = h - hb - fromBottomPixels
  71.     w1 = w0 + wb
  72.     h1 = h0 + hb
  73.     draw.text((w0, h0), text, font = font, fill = colour)
  74.     (fd, fn) = tempfile.mkstemp('.jpg')
  75.     os.fdopen(fd).close()
  76.     img.save(fn)
  77.     bmp = Image.open(fn)
  78.     bmp.save(destination)
  79.     os.remove(fn)
  80.  
  81.